package com.nlgc365.designpattern.Chapter04_Pattern.Behavior.P04_ChainOfResponsibility.pattern1.ByArray;

import java.util.ArrayList;
import java.util.List;

public class HandlerChain {
    private List<Handler> chain = new ArrayList<>();

    // Function: handle; used to add handler
    public void addHandler(Handler handler) {
        chain.add(handler);
    }

    // 函数: handle
    public void handle() {
        for (Handler handler : chain) {
            //处理当前节点处理器能够处理, 就完成当前职责链
            if (!handler.handle()) {
                break;
            }
        }
    }
}
